***********************
***********************

*	Rents, Resource Diversification, and the Collapse of Autocratic Regimes
*	Matthew Fails and Marc DuBuis
*	Forthcoming at Political Research Quartlery
*	This code: July 6, 2015

***********************
***********************

*	This is the code for Section 2 of the Web Appendix, which uses an alternative method to deal with missing data from the World Bank
*	See the appendix for more details

clear 
use "C:\Users\fails\Documents\My Dropbox\DuBuis - leader tenure\publication materials\data and code\FailsDuBuisReplicationData.dta", replace
tsset ccode year

*generate a sample marker for all autocracies as defined by GWF
*This variable becomes the sample identifier for all analyses

gen sample = .
replace sample = 0 if gwf_party==0 & gwf_party!=. & gwf_military==0 & gwf_military!=. & gwf_monarchy==0 & gwf_monarchy!=. & gwf_personal==0 & gwf_personal!=.
replace sample = 1 if gwf_party==1 | gwf_military==1  | gwf_monarchy==1  | gwf_personal==1 
label var sample "GWF Autocracy Sample"

sum gwf_fail if sample==1
tab gwf_fail if sample==1

*Some general data maintenance
*log values of income and population
gen lgdppc = log(rgdpch)
label var lgdppc "Log income per capita, PWT"

gen logpop = log(pop)
label var logpop "Log of population"

*creation of time polynomials and description of DV
generate tim = gwf_duration
generate tim2 = gwf_duration^2
generate tim3 = gwf_duration^3

sum tim

*gen laggrowth var
gen laggr = l.gr
label var laggr "One year lag in growth"

*generate Ross oil variable
gen ross_oilstate = 0
replace ross_oilstate =1 if oil_gas_valuePOP_2000>100
label var ross_oilstate "Oil producer, $100 per capita"

sort ccode year
gen coupatt = 0
replace coupatt = 1 if coup1==1 
label var coupatt "attempted coup during year"

gen lagcoupatt = l.coupatt

********************
********************

** Calculate key IV of interest as HH Index of Concentration

	
generate totalrent2_ap = coalrents+forestrents+mineralrents+natgasrents+oilrents+odarents_AD
label var totalrent2_ap "total rents as percentage of GDP, using AidData, appendix version"

gen coal_ap = coalrents/totalrent2_ap if totalrent2_ap>=0 & totalrent2_ap<=100 & coalrents!=.
gen forest_ap = forestrents/totalrent2_ap if totalrent2_ap>=0 & totalrent2_ap<=100 & forestrents!=.
gen mineral_ap = mineralrents/totalrent2_ap if totalrent2_ap>=0 & totalrent2_ap<=100 & mineralrents!=.
gen natgas_ap = natgasrents/totalrent2_ap if totalrent2_ap>=0 & totalrent2_ap<=100 & natgasrents!=.
gen oil_ap = oilrents/totalrent2_ap if totalrent2_ap>=0 & totalrent2_ap<=100 & oilrents!=.
gen oda_ap = odarents_AD/totalrent2_ap if totalrent2_ap>=0 & totalrent2_ap<=100 & odarents_AD!=. /*note that I am using AidData here*/

*if there is only one source of rents, then dividing by totalrents will lead to an adjusted score of 1
*then, when you eventually take 1-hhi, since hhi will be 1, you get a diversity score of 1

*then take the sum of the squared terms
gen coal_a2ap = coal_ap^2
gen forest_a2ap = forest_ap^2
gen mineral_a2ap = mineral_ap^2
gen natgas_a2ap = natgas_ap^2
gen oil_a2ap = oil_ap^2
gen oda_a2ap = oda_ap^2

gen hhi_ap = coal_a2ap+forest_a2ap+mineral_a2ap+natgas_a2ap+oil_a2ap+oda_a2ap
label var hhi_ap "HHI for rent sources, adjusted as share of all totalrent)

gen diverse_ap = 1-hhi_ap
label var diverse_ap "Rent diversification, appendix version"

gen divapdivap = diverse_ap*diverse_ap
label var divapdivap "quadratic term for diverse_a, excluding nonrents"	
	

	
*************TABLE A2 - PROBIT REGRESSION MODELS

*MODEL 1 
probit gwf_fail diverse_ap divapdivap totalrent2_ap lgdppc laggr gwf_party tim tim2 tim3 if sample==1,  cluster("gwf_casename")
outreg2 using "c:\data\DuBuis\m1.ascii", replace bdec(2) coefastr 

*MODEL 2 
probit gwf_fail diverse_ap divapdivap  ross_oilstate lgdppc laggr gwf_party tim tim2 tim3 if sample==1,  cluster("gwf_casename")
outreg2 using "c:\data\DuBuis\m1.ascii", replace bdec(2) coefastr 

